home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * *
- * MODULE : dialog.cpp *
- * *
- * Purpose: Dialog demonstrating use of Betedit *
- * *
- * Comments: Only demo code - not enough to build this .. *
- * *
- * History: Date Reason *
- * -------- ----------------------------------- *
- * *
- * 10/06/92 Created *
- * *
- **************************************************************************/
-
-
- #include <afxwin.h> /* required for all Windows applications */
- #include "dialog.h"
-
-
- BEGIN_MESSAGE_MAP( CObViewDlg, CModalDialog)
- ON_WM_PARENTNOTIFY()
- ON_WM_ACTIVATEAPP()
- ON_MESSAGE(BEM_NOTVALID, OnNotValid)
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Constructor with parameters
- // Calls base class constructor and saves the parameters for use
- //
- CObViewDlg::CObViewDlg(float* pYMax, float* pYMin, char* szTitle, CWnd* pParentWnd)
- : CModalDialog(IDD_VIEWPARAM, pParentWnd)
- {
- m_pYMax = pYMax;
- m_pYMin = pYMin;
- strcpy(m_szTitle, szTitle);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInitDialog:
- // Gets everything ready for display and use - just before display
- //
- BOOL CObViewDlg::OnInitDialog()
- {
- SetWindowText(m_szTitle); // Get the title OK
-
- // We have to set up our better edits as subclassed controls
- VERIFY(m_YMaxEdit.SubclassEdit(IDC_YAXMAX, this, -1000, 1000)); // Upper value
- m_YMaxEdit.SetValue(*m_pYMax);
- VERIFY(m_YMinEdit.SubclassEdit(IDC_YAXMIN, this, -1000, 1000));
- m_YMinEdit.SetValue(*m_pYMin);
-
- // Set validation override off
- m_bOverride = FALSE;
- return TRUE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnActivateApp : Notification of task switching.
- // We prevent validation of the contents of the controls when the
- // user switches to another app, and enable when switching back.
- //
- afx_msg void CObViewDlg::OnActivateApp(BOOL bActive, HANDLE hTask)
- {
- m_bOverride = !bActive; // Prevent activity when app deactivated
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnParentNotify : Notification of an action to child window.
- // We dont want to validate the contents of the controls when
- // the user presses the CANCEL button, so test for this.
- //
- afx_msg void CObViewDlg::OnParentNotify(UINT wParam, LONG lParam)
- {
- CPoint thePoint(LOWORD(lParam), HIWORD(lParam)); // Click co-ords
-
- if ((wParam == WM_LBUTTONDOWN) &&
- (ChildWindowFromPoint(thePoint) == GetDlgItem(IDCANCEL)))
- m_bOverride = TRUE; // Flag that cancel was pressed
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnNotValid : A control is invalid - give a message and retain focus
- // We use a separate message for this as this allows a delayed action
- // by using PostMessage - ensures changes in focus are over. Note that
- // we temporarily override validation while in this routine, in some
- // circumstances (user pressed Enter to select OK) this routine can provoke
- // extra validation messages via the BetEdit KillFocus checks!
- //
- afx_msg LONG CObViewDlg::OnNotValid(UINT wParam, LONG lParam)
- {
- if (!m_bOverride) // Only do something if the override is off
- {
- CWnd* pWnd = GetDlgItem(wParam); // Control with a problem
-
- m_bOverride = TRUE; // and override temporarily
- pWnd->SendMessage(BEM_VALIDATE, 1, 0); // Display an error message
- pWnd->SetFocus(); // Retain the focus
- pWnd->SendMessage(EM_SETSEL, 0, 0x7FFF); // Select all
- m_bOverride = FALSE; // Restore previous state
- }
- return 1;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnOK:
- // User has accepted data, return the results. Note that this relies
- // upon the saved pointer still being valid - users take note !
- //
- void CObViewDlg::OnOK()
- {
- float fMax, fMin;
-
- if (m_YMaxEdit.SendMessage(BEM_VALIDATE, 0, 0) == 0) // Check upper value
- {
- SendMessage(BEM_NOTVALID, IDC_YAXMAX, 0);
- return;
- }
- if (m_YMinEdit.SendMessage(BEM_VALIDATE, 0, 0) == 0) // Check upper value
- {
- SendMessage(BEM_NOTVALID, IDC_YAXMIN, 0);
- return;
- }
- fMax = m_YMaxEdit.GetValue(); // Get value as float
- fMin = m_YMinEdit.GetValue();
- if (fMax != fMin)
- {
- *m_pYMax = fMax;
- *m_pYMin = fMin;
- }
- else
- {
- MessageBox("Upper and lower values must be different", "Bad axes limits", MB_ICONEXCLAMATION);
- CWnd* pWnd = GetDlgItem(IDC_YAXMAX); // Control with a problem
- pWnd->SetFocus(); // Retain the focus
- pWnd->SendMessage(EM_SETSEL, 0, 0x7FFF); // Select all
- return;
- }
- EndDialog(IDOK); /* Exits the dialog box */
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnCancel:
- // User has given up - do likewise
- //
- void CObViewDlg::OnCancel()
- {
- EndDialog(IDCANCEL);
- }